In [5]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from scipy import stats
# In[16]:
get_ipython().system('pip install folium')
# In[18]:
# Load the dataset
df = pd.read_csv('/Users/vanshikakapur/Desktop/DV /prject_viz/crime_relabelled_with_geocode.csv')
df
Requirement already satisfied: folium in /opt/anaconda3/lib/python3.12/site-packages (0.19.5) Requirement already satisfied: branca>=0.6.0 in /opt/anaconda3/lib/python3.12/site-packages (from folium) (0.8.1) Requirement already satisfied: jinja2>=2.9 in /opt/anaconda3/lib/python3.12/site-packages (from folium) (3.1.4) Requirement already satisfied: numpy in /opt/anaconda3/lib/python3.12/site-packages (from folium) (1.26.4) Requirement already satisfied: requests in /opt/anaconda3/lib/python3.12/site-packages (from folium) (2.32.3) Requirement already satisfied: xyzservices in /opt/anaconda3/lib/python3.12/site-packages (from folium) (2022.9.0) Requirement already satisfied: MarkupSafe>=2.0 in /opt/anaconda3/lib/python3.12/site-packages (from jinja2>=2.9->folium) (2.1.3) Requirement already satisfied: charset-normalizer<4,>=2 in /opt/anaconda3/lib/python3.12/site-packages (from requests->folium) (3.3.2) Requirement already satisfied: idna<4,>=2.5 in /opt/anaconda3/lib/python3.12/site-packages (from requests->folium) (3.7) Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/anaconda3/lib/python3.12/site-packages (from requests->folium) (2.2.3) Requirement already satisfied: certifi>=2017.4.17 in /opt/anaconda3/lib/python3.12/site-packages (from requests->folium) (2025.1.31)
Out[5]:
| Report ID | Date Reported | Date Occurred | Time Occurred | Crime Type | Description | Location | Status | Full Address | Latitude | Longitude | |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 252005 | 4/22/2025 | 4/22/2025 | 08:00:00 | Fraud | FALSE GOVERNMENT ISSUED IDENTIFICATION | EIGENMANN HALL | OPEN CASE | EIGENMANN HALL, Bloomington, IN | 39.171159 | -86.508805 |
| 1 | 252004 | 4/22/2025 | 3/31/2025 | 11:30:00 | Theft | THEFT FROM BUILDING LESS THAN $750 | MCNUTT QUAD | OPEN CASE | MCNUTT QUAD, Bloomington, IN | 39.176291 | -86.520191 |
| 2 | 251997 | 4/22/2025 | 4/12/2025 | 22:00:00 | Larceny | ILLEGAL CONSUMPTION/POSSESSION OF ALCOHOL BY M... | FOREST QUAD | REFERRED TO UNIVERSITY OFFICIALS FOR REVIEW | FOREST QUAD, Bloomington, IN | 39.164555 | -86.512940 |
| 3 | 251996 | 4/22/2025 | 4/12/2025 | 22:15:00 | Larceny | ILLEGAL CONSUMPTION/POSSESSION OF ALCOHOL BY M... | BRISCOE QUAD | REFERRED TO UNIVERSITY OFFICIALS FOR REVIEW | BRISCOE QUAD, Bloomington, IN | 39.178438 | -86.519964 |
| 4 | 251995 | 4/22/2025 | 4/12/2025 | 22:15:00 | Larceny | ILLEGAL CONSUMPTION/POSSESSION OF ALCOHOL BY M... | WILLKIE MASON HALL | REFERRED TO UNIVERSITY OFFICIALS FOR REVIEW | WILLKIE MASON HALL, Bloomington, IN | 39.167881 | -86.509958 |
| ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
| 491 | 250844 | 2/22/2025 | 2/21/2025 | 21:00:00 | Fraud | FALSE GOVERNMENT ISSUED IDENTIFICATION | EIGENMANN HALL | REFERRED TO UNIVERSITY OFFICIALS FOR REVIEW | EIGENMANN HALL, Bloomington, IN | 39.171159 | -86.508805 |
| 492 | 250832 | 2/21/2025 | 2/21/2025 | 09:00:00 | Theft | ALL OTHER THEFT LESS THAN $750 | FOSTER EXTERIOR GROUNDS | OPEN CASE | FOSTER EXTERIOR GROUNDS, Bloomington, IN | 39.169574 | -86.538555 |
| 493 | 250826 | 2/21/2025 | 1/10/2025 | 15:00:00 | Fraud | FALSE GOVERNMENT ISSUED IDENTIFICATION | CAMPUS VIEW APTS. | NO ARREST | CAMPUS VIEW APTS., Bloomington, IN | 39.173544 | -86.509192 |
| 494 | 250817 | 2/21/2025 | 2/21/2025 | 03:21:00 | Misdemeanor | OPERATING WHILE INTOXICATED - ENDANGERMENT | DUNN STREET/SOUTH OF 10TH | SUSPECT ARRESTED | DUNN STREET/SOUTH OF 10TH, Bloomington, IN | 39.187390 | -86.528468 |
| 495 | 250815 | 2/21/2025 | 2/21/2025 | 00:20:00 | Larceny | ILLEGAL CONSUMPTION/POSSESSION OF ALCOHOL BY M... | SIGMA PI | REFERRED TO UNIVERSITY OFFICIALS FOR REVIEW | SIGMA PI, Bloomington, IN | 39.181621 | -86.511011 |
496 rows × 11 columns
In [7]:
import pandas as pd
import plotly.express as px
# Make sure Date Reported is datetime
df["Date Reported"] = pd.to_datetime(df["Date Reported"])
# Extract month
df["Month"] = df["Date Reported"].dt.to_period("M").astype(str)
# Group by Crime Typeand Month to get frequency
bar_data = df.groupby(["Month", "Crime Type"]).size().reset_index(name="Frequency")
# Create animated bar chart
fig = px.bar(
bar_data,
x="Crime Type",
y="Frequency",
color="Crime Type",
animation_frame="Month",
animation_group="Crime Type",
title="Animated Bar Chart: Crime TypeFrequency Over Time",
range_y=[0, bar_data["Frequency"].max() + 10],
template="plotly_white"
)
# Optional: Sort bars within each frame
fig.update_layout(xaxis={'categoryorder':'total descending'})
fig.show()
In [ ]: